-
Notifications
You must be signed in to change notification settings - Fork 1
CreateSpark #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CreateSpark #124
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a createSpark() factory method that provides a unified interface for creating either SparkMax or SparkFlex motor controllers based on the MotorConfig parameter. This simplifies client code by allowing dynamic selection of the appropriate Spark controller type without needing to explicitly call createSparkMax() or createSparkFlex().
Changes:
- Added two overloaded
createSpark()methods that dispatch to the appropriatecreateSparkMax()orcreateSparkFlex()method based on themotorConfig.controllerType - The first overload uses default Spark configuration, while the second accepts a custom
SparkBaseConfig
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case SPARK_FLEX: | ||
| return createSparkFlex(id, motorConfig, config); | ||
| default: | ||
| return null; |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default case returns null, which could lead to NullPointerExceptions if an unexpected controllerType is passed. While this pattern is consistent with other methods in this class (e.g., getConfigAccessor at line 157-158, createConfig at line 161-171, getControllerType at line 180), consider whether it would be safer to throw an IllegalArgumentException with a descriptive message explaining that the controllerType is unsupported. This would make debugging easier and fail faster if an invalid configuration is used.
| return null; | |
| throw new IllegalArgumentException( | |
| "Unsupported controllerType in MotorControllerFactory.createSpark: " | |
| + motorConfig.controllerType); |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@CoolSpy3 could you review pls |
CoolSpy3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small notes.
src/test/java/org/carlmontrobotics/lib199/MotorControllerFactoryTest.java
Outdated
Show resolved
Hide resolved
…reateSpark creates the right motor type
|
@CoolSpy3 Done 👍 |
CoolSpy3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great; thanks! This looks good ✅ Just fix the javadoc errors. (I think the problem might be that the ...s are causing Javadoc to look for varargs declarations that don't exist, but idk for sure.)
CoolSpy3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm. Sorry, GitHub was showing me the not-most-recent commit :P
This add a createSpark() method. It returns a SparkBase initialized to a SparkMax/Flex depending on the motorConfig passed in.